<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-size: 14px;
            background-color: #f1f3f4;
        }

        .blank {
            height: 7px;
        }

        div {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .content {
            margin: 15px;
        }

        .item {
            display: flex;
            align-items: center;
            padding: 15px 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            background-color: #fff;
            justify-content: space-between;
            box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.07);
        }

        .con-l {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 1px solid #dedede;
            background: #fff;
            margin-right: 15px;
        }
        .con-c {
            flex:1;
        }

        .con-r {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-right:5px;
        }

        .logo {
            width: 50px;
            height: 45px;
            margin-bottom: 10px;
        }

        .logo-img {
            width: 100%;
            height: 100%;
        }

        .qr-code {
            width: 100px;
            height: 100px;
        }

        .code-img {
            width: 100%;
            height: 100%;
        }

        .item-weight {
            font-weight: bold;
            margin-bottom: 10px;
        }

        .weight-l {
            font-size: 20px;
        }

        .weight-r {
            font-size: 20px;
            font-weight: bold;
        }

        .item-con {
            margin-bottom: 8px;
            font-size: 16px;
        }

        .item-con-title {
            color: #000000;
        }
    </style>
    <script src="js/qrcode.js"></script>
    <script type="text/javascript">
		function scanprint(){
			var datalistdiv = document.getElementById("show");
			window.connect.print(datalistdiv.offsetLeft, datalistdiv.offsetTop, datalistdiv.offsetWidth, datalistdiv.offsetHeight);
		}
		function feed(){
			window.connect.doFeed();
		}
		function getQrCode(codeid, id) {
			var qrcode = new QRCode(codeid, {
				text: id,
				width: 100,
				height: 100,
				colorDark: "#000000",
				colorLight: "#ffffff",
				correctLevel: QRCode.CorrectLevel.L
			});
			let canvas = qrcode._el.querySelector("canvas");//获取生成二维码中的canvas，并将canvas转换成base64
            var base64Text = canvas.toDataURL("image/png");
            return base64Text;
		}
		function getLabel(jsonStr){
            var jsonObj = JSON.parse(jsonStr);
			var html = '';
			html = html + '<div class="blank">' + '</div>'
            html = html + '<div class="item">'
            html = html + '<div class="con-c">'
            html = html + '<div class="item-weight">'
            html = html + '<span class="weight-l">' + '重量：' + '</span>'
            html = html + '<span class="weight-r">' + jsonObj.weight + '</span>'
            html = html + '<span class="weight-l">' + 'kg' + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '编号：' + '</span>'
            html = html + '<span>' + jsonObj.code + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '医院：' + '</span>'
            html = html + '<span>' + jsonObj.hospitalBaseName + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '科室：' + '</span>'
            html = html + '<span>' + jsonObj.hospitalDepartName + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '类型：' + '</span>'
            html = html + '<span>' + jsonObj.wasteClassifyName + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '发布人员：' + '</span>'
            html = html + '<span>' + jsonObj.handUserStaffName + '</span>'
            html = html + '</div>'
            html = html + '<div class="item-con">'
            html = html + '<span class="item-con-title">' + '日期：' + '</span>'
            html = html + '<span>' + jsonObj.createTime + '</span>'
            html = html + '</div>'
            html = html + '</div>'
            html = html + '<div class="con-r">'
            html = html + '<div class="logo">'
            html = html +  '<img src="./waste_label.png" class="logo-img" />'
            html = html + '</div>'
            html = html + '<div class="qr-code" id="qrcode">' +  '</div>'
            html = html + '</div>'
            html = html + '</div>'
            html = html + '<div class="blank">' + '</div>'
			document.getElementById('show').innerHTML = html
			// 生成二维码
			getQrCode('qrcode', jsonObj.qrCode)
			// 执行打印
			scanprint();
		}
    </script>
</head>

<body>
    <div class="content">
        <div class="con-item" id="show"></div>
    </div>
</body>

</html>